package org.dragon.mappers;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.dragon.models.Privilege;

@Mapper
public interface PrivilegeMapper {
    @Delete({
        "delete from privilege",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into privilege (id, uri, ",
        "enabled, create_time)",
        "values (#{id,jdbcType=BIGINT}, #{uri,jdbcType=VARCHAR}, ",
        "#{enabled,jdbcType=BIT}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(Privilege row);

    @Select({
        "select",
        "id, uri, enabled, create_time",
        "from privilege",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uri", property="uri", jdbcType=JdbcType.VARCHAR),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Privilege selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, uri, enabled, create_time",
        "from privilege"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uri", property="uri", jdbcType=JdbcType.VARCHAR),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Privilege> selectAll();

    @Update({
        "update privilege",
        "set uri = #{uri,jdbcType=VARCHAR},",
          "enabled = #{enabled,jdbcType=BIT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Privilege row);
}